package cn.edu.whu.MVCByHand.service;

import cn.edu.whu.MVCByHand.annotation.MyService;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

@MyService
public class TestServiceImpl implements TestService {
	private List<String> classNames = new ArrayList<>();

	@Override
	public void printParam(String param) {
		System.out.println("接收到的参数为： "+param);
//		URL resource = this.getClass().getClassLoader().getResource("/");
//		URL resource2 = this.getClass().getClassLoader().getResource("myapplication.properties");
//		URL resource3 = this.getClass().getClassLoader().getResource("com.demo.myservlet");
//		doScanner(param);
	}
	public static void main(String[] args) {
		TestServiceImpl testService = new TestServiceImpl();
		testService.printParam("d");
	}

	private void doScanner(String packageName) {
		URL url  =this.getClass().getClassLoader().getResource(""+packageName.replaceAll("\\.", "/"));
		File dir = new File(url.getFile());
		for (File file : dir.listFiles()) {
			if(file.isDirectory()){
				//递归读取包
				doScanner(packageName+"."+file.getName());
			}else{
				String className =packageName +"." +file.getName().replace(".class", "");
				classNames.add(className);
			}
		}
		System.out.println(classNames);
	}
}
